<%#
kind: iPXE
model: ProvisioningTemplate
name: iPXE intermediate script
snippet: false
description: |
  This template is returned when ?bootstrap=1 URL parameter is provided.
  It is used in pure iPXE environment and it's purpose is to perform another iPXE template call,
  but with MAC address(es) of the server in order to find appropriate host record in the inventory.
  See https://docs.theforeman.org/nightly/Provisioning_Guide/index-foreman-el.html#Configuring_Networking-Configuring_gPXE_to_Reduce_Provisioning_Times
-%>
#!ipxe
# Intermediate iPXE script to report MAC address to Foreman
<% (0..32).each do |i| -%>

:net<%= i %>
isset ${net<%= i -%>/mac} || goto no_nic
dhcp net<%= i -%> || goto net<%= i+1 %>
chain <%= foreman_url('iPXE', {}, { mac: "${net#{i}/mac}" }) %> || goto net<%= i+1 %>
<% end -%>

:net33
goto no_nic

exit 0

:no_nic
echo Failed to chainload from any network interface
sleep 30
exit 1
